package com.xjust.service.impl;

import com.xjust.Mapper.EmployeeMapper;
import com.xjust.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.DayOfWeek;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class EmployeeServiceImpl implements EmployeeService {
    @Autowired
   private EmployeeMapper employeeMapper;
    //获取看诊医生
    @Override
    public List<Map<String, Object>> getEmployee(Integer deptmentId, Integer registLevelId) {
        List<Map<String, Object>> list = employeeMapper.selectEmployee(deptmentId,registLevelId);
        DayOfWeek week = LocalDateTime.now().getDayOfWeek();
        Integer amOrPm;
        if(LocalDateTime.now().getHour()>12){
            amOrPm = 1;
        }else{
            amOrPm = 0;
        }
        List<Map<String, Object>> selectDoctorList = new ArrayList<>();
        for(Map<String,Object> doctor:list){
            String week_rule = (String) doctor.get("week_rule");
            String noon = week_rule.substring((week.getValue()-1)*2,(week.getValue()-1)*2+2);

            if(noon.charAt(amOrPm) == '1'){
                selectDoctorList.add(doctor);
                System.out.println("添加了一位医生");
            }else{
                System.out.println("没有满足医生");
            }
        }
        return selectDoctorList;
    }
    //获取医生已用号额
    @Override
    public List<Map<String,Object>> getDoctorBydepementId(Integer deptId) {
        List<Map<String,Object>> map = employeeMapper.selectDoctorBydepementId(deptId);
        return map;
    }

    @Override
    public Integer getDepartmentId(Integer id, String password) {
        Integer deptId =  employeeMapper.getDepartId(id,password);
        return deptId;
    }
}
